home *** CD-ROM | disk | FTP | other *** search
/ Champak 145 / (Vol 145) Dec 21 2011.iso / Games / kupidon-strike.swf / scripts / __Packages / mochi / MochiScores.as < prev    next >
Encoding:
Text File  |  2011-12-21  |  5.7 KB  |  197 lines

  1. class mochi.MochiScores
  2. {
  3.    static var boardID;
  4.    static var onClose;
  5.    static var onError;
  6.    function MochiScores()
  7.    {
  8.    }
  9.    static function setBoardID(boardID)
  10.    {
  11.       mochi.MochiScores.boardID = boardID;
  12.       mochi.MochiServices.send("scores_setBoardID",{boardID:boardID});
  13.    }
  14.    static function showLeaderboard(options)
  15.    {
  16.       if(options.clip == null || options.clip == undefined)
  17.       {
  18.          options.clip = mochi.MochiServices.clip;
  19.       }
  20.       if(options.clip != mochi.MochiServices.clip || mochi.MochiServices.childClip._target == undefined)
  21.       {
  22.          mochi.MochiServices.disconnect();
  23.          mochi.MochiServices.connect(mochi.MochiServices.id,options.clip);
  24.       }
  25.       delete options.clip;
  26.       if(options.name != null)
  27.       {
  28.          if(typeof options.name == "object")
  29.          {
  30.             if(options.name.text != undefined)
  31.             {
  32.                options.name = options.name.text;
  33.             }
  34.          }
  35.       }
  36.       if(options.score != null)
  37.       {
  38.          if(options.score instanceof TextField)
  39.          {
  40.             if(options.score.text != undefined)
  41.             {
  42.                options.score = options.score.text;
  43.             }
  44.          }
  45.          else if(options.score instanceof mochi.MochiDigits)
  46.          {
  47.             options.score = options.score.value;
  48.          }
  49.          var _loc1_ = Number(options.score);
  50.          if(isNaN(_loc1_))
  51.          {
  52.             trace("ERROR: Submitted score \'" + options.score + "\' will be rejected, score is \'Not a Number\'");
  53.          }
  54.          else if(_loc1_ == -Infinity || _loc1_ == Infinity)
  55.          {
  56.             trace("ERROR: Submitted score \'" + options.score + "\' will be rejected, score is an infinite");
  57.          }
  58.          else
  59.          {
  60.             if(Math.floor(_loc1_) != _loc1_)
  61.             {
  62.                trace("WARNING: Submitted score \'" + options.score + "\' will be truncated");
  63.             }
  64.             options.score = _loc1_;
  65.          }
  66.       }
  67.       if(options.onDisplay != null)
  68.       {
  69.          options.onDisplay();
  70.       }
  71.       else
  72.       {
  73.          mochi.MochiServices.clip.stop();
  74.       }
  75.       if(options.onClose != null)
  76.       {
  77.          mochi.MochiScores.onClose = options.onClose;
  78.       }
  79.       else
  80.       {
  81.          mochi.MochiScores.onClose = function()
  82.          {
  83.             mochi.MochiServices.clip.play();
  84.          };
  85.       }
  86.       if(options.onError != null)
  87.       {
  88.          mochi.MochiScores.onError = options.onError;
  89.       }
  90.       else
  91.       {
  92.          mochi.MochiScores.onError = mochi.MochiScores.onClose;
  93.       }
  94.       if(options.boardID == null)
  95.       {
  96.          if(mochi.MochiScores.boardID != null)
  97.          {
  98.             options.boardID = mochi.MochiScores.boardID;
  99.          }
  100.       }
  101.       mochi.MochiServices.send("scores_showLeaderboard",{options:options},null,mochi.MochiScores.doClose);
  102.    }
  103.    static function closeLeaderboard()
  104.    {
  105.       mochi.MochiServices.send("scores_closeLeaderboard");
  106.    }
  107.    static function getPlayerInfo(callbackObj, callbackMethod)
  108.    {
  109.       mochi.MochiServices.send("scores_getPlayerInfo",null,callbackObj,callbackMethod);
  110.    }
  111.    static function submit(score, name, callbackObj, callbackMethod)
  112.    {
  113.       score = Number(score);
  114.       if(isNaN(score))
  115.       {
  116.          trace("ERROR: Submitted score \'" + String(score) + "\' will be rejected, score is \'Not a Number\'");
  117.       }
  118.       else if(score == -Infinity || score == Infinity)
  119.       {
  120.          trace("ERROR: Submitted score \'" + String(score) + "\' will be rejected, score is an infinite");
  121.       }
  122.       else
  123.       {
  124.          if(Math.floor(score) != score)
  125.          {
  126.             trace("WARNING: Submitted score \'" + String(score) + "\' will be truncated");
  127.          }
  128.          score = Number(score);
  129.       }
  130.       mochi.MochiServices.send("scores_submit",{score:score,name:name},callbackObj,callbackMethod);
  131.    }
  132.    static function requestList(callbackObj, callbackMethod)
  133.    {
  134.       mochi.MochiServices.send("scores_requestList",null,callbackObj,callbackMethod);
  135.    }
  136.    static function scoresArrayToObjects(scores)
  137.    {
  138.       var _loc5_ = {};
  139.       var _loc1_ = undefined;
  140.       var _loc4_ = undefined;
  141.       var _loc2_ = undefined;
  142.       var _loc6_ = undefined;
  143.       for(var _loc8_ in scores)
  144.       {
  145.          if(typeof scores[_loc8_] == "object")
  146.          {
  147.             if(scores[_loc8_].cols != null && scores[_loc8_].rows != null)
  148.             {
  149.                _loc5_[_loc8_] = [];
  150.                _loc2_ = scores[_loc8_];
  151.                _loc4_ = 0;
  152.                while(_loc4_ < _loc2_.rows.length)
  153.                {
  154.                   _loc6_ = {};
  155.                   _loc1_ = 0;
  156.                   while(_loc1_ < _loc2_.cols.length)
  157.                   {
  158.                      _loc6_[_loc2_.cols[_loc1_]] = _loc2_.rows[_loc4_][_loc1_];
  159.                      _loc1_ = _loc1_ + 1;
  160.                   }
  161.                   _loc5_[_loc8_].push(_loc6_);
  162.                   _loc4_ = _loc4_ + 1;
  163.                }
  164.             }
  165.             else
  166.             {
  167.                _loc5_[_loc8_] = {};
  168.                for(var _loc7_ in scores[_loc8_])
  169.                {
  170.                   _loc5_[_loc8_][_loc7_] = scores[_loc8_][_loc7_];
  171.                }
  172.             }
  173.          }
  174.          else
  175.          {
  176.             _loc5_[_loc8_] = scores[_loc8_];
  177.          }
  178.       }
  179.       return _loc5_;
  180.    }
  181.    static function doClose(args)
  182.    {
  183.       if(args.error == true)
  184.       {
  185.          if(args.errorCode == undefined)
  186.          {
  187.             args.errorCode = "IOError";
  188.          }
  189.          mochi.MochiScores.onError.apply(null,[args.errorCode]);
  190.       }
  191.       else
  192.       {
  193.          mochi.MochiScores.onClose.apply();
  194.       }
  195.    }
  196. }
  197.